package com.yanqu.road.server.gameplayer.module.activity.apprentice;

import com.yanqu.road.dao.impl.activity.apprentice.ApprenticeUserPatronsTalentDataDaoImpl;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.apprentice.ApprenticeConvertResult;
import com.yanqu.road.entity.activity.apprentice.ApprenticeShopTypePropData;
import com.yanqu.road.entity.activity.apprentice.config.ApprenticeConfig;
import com.yanqu.road.entity.activity.apprentice.config.ApprenticeLevelConfig;
import com.yanqu.road.entity.activity.apprentice.config.ApprenticeProjectConfig;
import com.yanqu.road.entity.activity.apprentice.data.ApprenticeUserPatronsTalentData;
import com.yanqu.road.entity.activity.args.ActivityValueParamArgs;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.config.patrons.PatronsInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.eOccupationType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.log.apprentice.LogApprenticeTalentConvertProp;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.ApprenticeProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.helper.SignHelper;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.apprentice.ApprenticeMgr;
import com.yanqu.road.server.manger.activity.apprentice.pb.ApprenticePb;
import com.yanqu.road.server.manger.config.MallMgr;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class ApprenticeModule extends GeneralModule {

    /**
     * 玩家门客天资数据
     */
    private Map<Integer, ApprenticeUserPatronsTalentData> userPatronsTalentDataMap = new ConcurrentHashMap<>();

    public ApprenticeModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        ApprenticeUserPatronsTalentDataDaoImpl dao = new ApprenticeUserPatronsTalentDataDaoImpl();
        this.userPatronsTalentDataMap = dao.getApprenticeUserPatronsTalentDataMap(player.getUserId());
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        for (ApprenticeUserPatronsTalentData data : this.userPatronsTalentDataMap.values()) {
            if (data.isInsertOption()) {
                new ApprenticeUserPatronsTalentDataDaoImpl().add(data);
            } else if (data.isUpdateOption()) {
                new ApprenticeUserPatronsTalentDataDaoImpl().update(data);
            }
        }
        return true;
    }

    @Override
    public void afterLogin() {
        //推送活动配置
        this.syncConfig();
        //上跨服
        this.afterLoginCross();
        //同步门客天资数据（玩家维度）
        this.syncUserPatronsTalentData();
    }

    /**
     * 跨服登录后处理
     */
    private void afterLoginCross() {
        //同步配置
        Map<Integer, ApprenticeConfig> configMap = ApprenticeMgr.getConfigMap();
        for (ApprenticeConfig config : configMap.values()) {
            ActivityInfo activityInfo = config.getActivityInfo();
            if (!ActivityHelper.activityInShowTime(activityInfo)) {
                continue;
            }
            //上跨服
            ApprenticeProto.ApprenticeAfterLoginCrossReqMsg.Builder builder = ApprenticeProto.ApprenticeAfterLoginCrossReqMsg.newBuilder();
            builder.setActivityId(config.getActivityInfo().getActivityId());
            player.sendPacket(Protocol.C2_APPRENTICE_AFTER_LOGIN, builder);
        }
    }

    /**
     * 同步配置
     */
    public void syncConfig() {
        //判断系统是否解锁
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Apprentice.getValue())) {
            return;
        }
        //同步配置
        Map<Integer, ApprenticeConfig> configMap = ApprenticeMgr.getConfigMap();
        for (ApprenticeConfig config : configMap.values()) {
            if (!ActivityHelper.activityInShowTime(config.getActivityInfo())) {
                continue;
            }
            ApprenticeProto.ApprenticeSyncConfigMsg.Builder builder = ApprenticeProto.ApprenticeSyncConfigMsg.newBuilder();
            builder.setActivityId(config.getActivityInfo().getActivityId());
            //等级配置
            for (ApprenticeLevelConfig levelConfig : config.getLevelConfigMap().values()) {
                builder.addLevelConfigs(ApprenticePb.buildLevelConfig(levelConfig));
            }
            //项目配置
            for (ApprenticeProjectConfig projectConfig : config.getProjectConfigMap().values()) {
                ApprenticeProto.ApprenticeProjectConfig.Builder projectBuilder = ApprenticePb.buildProjectConfig(projectConfig);
                projectBuilder.setName(ServerLanguageMgr.getContent(projectConfig.getName(), player.getLanguage()));
                projectBuilder.setDesc(ServerLanguageMgr.getContent(projectConfig.getDesc(), player.getLanguage()));
                projectBuilder.setPlaceName(ServerLanguageMgr.getContent(projectConfig.getPlaceName(), player.getLanguage()));
                projectBuilder.setPlaceDesc(ServerLanguageMgr.getContent(projectConfig.getPlaceDesc(), player.getLanguage()));
                builder.addProjectConfigs(projectBuilder);
            }
            //推送
            player.sendPacket(Protocol.U_APPRENTICE_SYNC_CONFIG, builder);
        }
    }

    /**
     * 获取活动配置
     * @param activityId
     * @return
     */
    public ApprenticeConfig getConfig(int activityId) {
        return ApprenticeMgr.getConfig(activityId);
    }

    /**
     * 通用检测
     * @param activityId
     * @throws BusinessException
     */
    private void commonCheck(int activityId, boolean checkInTime) throws BusinessException {
        //判断系统是否解锁
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Apprentice.getValue())) {
            throw BusinessException.newException(GameErrorCode.E_SYSTEM_NO_OPEN);
        }
        //配置是否存在
        ApprenticeConfig config = this.getConfig(activityId);
        if (config == null) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_CONFIG_NOT_FOUND);
        }
        //活动是否进行中
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        if (activityInfo == null) {
            throw BusinessException.newException(GameErrorCode.E_ACTIVITY_NO_FOUND);
        }
        if (!ActivityHelper.activityInShowTime(activityInfo)) {
            throw BusinessException.newException(GameErrorCode.E_ACTIVITY_OVER_TIME);
        }
        if (checkInTime && !ActivityHelper.activityInTime(activityInfo)) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_NOT_IN_TIME);
        }
    }

    /**
     * 进入活动
     * @param reqMsg
     * @return
     */
    public void enterActivity(ApprenticeProto.ApprenticeEnterActivityReqMsg reqMsg) throws BusinessException {
        this.commonCheck(reqMsg.getActivityId(), true);
        ApprenticeProto.ApprenticeEnterActivityReqMsg.Builder builder = reqMsg.toBuilder();
        //获取玩家baseInfo
        UserBaseInfo userBaseInfo = UserMgr.parseUserBaseInfo(player.getUserInfo(), GameServer.getInstance().getServerId());
        if (userBaseInfo == null) {
            throw new BusinessException(GameErrorCode.E_APPRENTICE_USER_BASE_NOT_FOUND);
        }
        builder.setUserInfo(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
        //上跨服
        player.sendPacket(Protocol.C2_APPRENTICE_ENTER_ACTIVITY, builder);
    }

    /**
     * 执行项目
     * @param reqMsg
     * @throws BusinessException
     */
    public void doProjects(ApprenticeProto.ApprenticeDoProjectReqMsg reqMsg) throws BusinessException {
        //通用检测
        this.commonCheck(reqMsg.getActivityId(), true);
        //预扣
        ApprenticeConfig config = this.getConfig(reqMsg.getActivityId());
        ApprenticeLevelConfig levelConfig = config.getLevelConfig(reqMsg.getLevel());
        if (levelConfig == null) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_LEVEL_CONFIG_NOT_FOUND);
        }
        Property cost = new Property(config.getAPPRENTICE_ITEM_ID(), levelConfig.getConsume());
        //判断道具是否足够
        if (!player.getModule(CurrencyModule.class).currencyIsEnough(cost)) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_ENERGY_NOT_ENOUGH);
        }
        //预扣除
        player.getModule(PreReduceModule.class).preReduce(cost);
        //上跨服
        player.sendPacket(Protocol.C2_APPRENTICE_DO_PROJECT, reqMsg.toBuilder());
    }

    /**
     * 日志列表
     * @param reqMsg
     * @return
     */
    public void getLogLis(ApprenticeProto.ApprenticeGetLogListReqMsg reqMsg) throws BusinessException {
        this.commonCheck(reqMsg.getActivityId(), false);
        //上跨服
        player.sendPacket(Protocol.C2_APPRENTICE_GET_LOG_LIST, reqMsg.toBuilder());
    }

    /**********************************************跨服返回************************************************/

    /**
     * 跨服返回-进入活动
     * @param respMsg
     */
    public void enterActivityFromCross(ApprenticeProto.ApprenticeEnterActivityRespMsg respMsg) {
        if (respMsg.hasInitReward() && !StringUtils.isNullOrEmpty(respMsg.getInitReward())) {
            //添加奖励
            player.getModule(CurrencyModule.class).addCurrency(respMsg.getInitReward(), eLogMoneyType.Apprentice, eLogMoneyType.ApprenticeInitUserReward);
        }
        //返回
        player.sendPacket(Protocol.U_APPRENTICE_ENTER_ACTIVITY, respMsg.toBuilder());
    }

    /**
     * 跨服返回-执行项目
     * @param respMsg
     */
    public void doProjectsFromCross(ApprenticeProto.ApprenticeDoProjectRespMsg respMsg) {
        ApprenticeConfig config = this.getConfig(respMsg.getActivityId());
        if (config == null) {
            log.error("爱徒养成-跨服返回-执行项目-配置未找到：{}，{}", respMsg.getActivityId());
            return;
        }

        //清理预扣除
        ApprenticeLevelConfig levelConfig = config.getLevelConfig(respMsg.getLevel());
        Property cost = new Property(config.getAPPRENTICE_ITEM_ID(), levelConfig.getConsume());
        player.getModule(PreReduceModule.class).restorePreReduce(cost);

        if (respMsg.getRet() == 0) {
            //扣除道具
            player.getModule(CurrencyModule.class).removeCurrency(cost, eLogMoneyType.Apprentice, eLogMoneyType.ApprenticeDoProjectsCost);

            if (respMsg.hasProgramResult()) {
                if (respMsg.getProgramResult().hasReward()) {
                    String reward = respMsg.getProgramResult().getReward();
                    //添加奖励
                    player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Apprentice, eLogMoneyType.ApprenticeDoProjectsReward);
                }
                //添加玩家维度的天资数据
                for (ApprenticeProto.ApprenticeTalentData talentData : respMsg.getProgramResult().getAddTalentList()) {
                    this.addPatronsTalent(config.getSHOW_PARTON_GET(), talentData.getTalentType(), talentData.getTalentValue());
                }
            }
            if (respMsg.hasUserData()) {
                //积分变更
                this.scoreChange(respMsg.getActivityId(), respMsg.getUserData().getAllTalent());
            }
        }
        //返回
        player.sendPacket(Protocol.U_APPRENTICE_DO_PROJECT, respMsg.toBuilder());
    }

    /**
     * 跨服返回-登录后处理
     * @param respMsg
     */
    public void afterLoginFromCross(ApprenticeProto.ApprenticeAfterLoginCrossRespMsg respMsg) {
        if (respMsg.hasUserData()) {
            //积分变更
            this.scoreChange(respMsg.getActivityId(), respMsg.getUserData().getAllTalent());
        }
    }

    /**
     * 积分变更
     * @param activityId
     * @param score
     */
    public synchronized void scoreChange(int activityId, long score) {
        //成就变更
        ActivityValueParamArgs args = new ActivityValueParamArgs(activityId, score, "");
        player.notifyListener(eGamePlayerEventType.ApprenticeScoreAchievement.getValue(), args);
        //榜单变更
        ActivityValueParamArgs rankArgs = new ActivityValueParamArgs(activityId, score, "");
        player.notifyListener(eGamePlayerEventType.ApprenticeScoreRank.getValue(), rankArgs);
    }

    /********************************************门客天资数据（玩家维度）************************************************/

    /**
     * 同步门客天资数据（玩家维度）
     */
    public void syncUserPatronsTalentData() {
        Map<Integer, ApprenticeUserPatronsTalentData> map = this.getUserPatronsTalentDataMap();
        if (map != null && !map.isEmpty()) {
            ApprenticeProto.ApprenticeSyncPatronsTalentDataMsg.Builder msg = ApprenticeProto.ApprenticeSyncPatronsTalentDataMsg.newBuilder();
            for (ApprenticeUserPatronsTalentData data : map.values()) {
                ApprenticeProto.ApprenticePatronsTalentData.Builder builder = ApprenticeProto.ApprenticePatronsTalentData.newBuilder();
                builder.setMallShopType(data.getMallShopType());
                builder.setTalent1(data.getTalent1());
                builder.setTalent2(data.getTalent2());
                builder.setTalent3(data.getTalent3());
                builder.setTalent4(data.getTalent4());
                builder.setTalent5(data.getTalent5());
                builder.setHistoryTalent1(data.getHistoryTalent1());
                builder.setHistoryTalent2(data.getHistoryTalent2());
                builder.setHistoryTalent3(data.getHistoryTalent3());
                builder.setHistoryTalent4(data.getHistoryTalent4());
                builder.setHistoryTalent5(data.getHistoryTalent5());
                builder.setConvertPropNum(data.getConvertPropNum());
                msg.addPatronsTalentData(builder);
            }
            player.sendPacket(Protocol.U_APPRENTICE_SYNC_PATRONS_TALENT_DATA, msg);
        }
    }

    /**
     * 获取门客天资数据MAP
     * @return
     */
    public Map<Integer, ApprenticeUserPatronsTalentData> getUserPatronsTalentDataMap() {
        return this.userPatronsTalentDataMap;
    }

    /**
     * 增加天资
     * @param mallShopType
     * @param talentType
     * @param talentValue
     */
    public void addPatronsTalent(int mallShopType, int talentType, long talentValue) {
        ApprenticeUserPatronsTalentData userPatronsTalentData = this.getPatronsTalentDataOrCreate(mallShopType);
        userPatronsTalentData.addTalent(talentType, talentValue);
        //同一下
        this.syncUserPatronsTalentData();

        if (talentValue > 0) {
            List<Long> args = new ArrayList<>();
            args.add(Long.valueOf(mallShopType));
            args.add(talentValue);
            player.notifyListener(eGamePlayerEventType.ApprenticeTalentAmount.getValue(), args);
        }
    }

    /**
     * 获取门客天资数据
     * @param mallShopType
     * @return
     */
    private ApprenticeUserPatronsTalentData getPatronsTalentDataOrCreate(int mallShopType) {
        ApprenticeUserPatronsTalentData userPatronsTalentData = this.userPatronsTalentDataMap.get(mallShopType);
        if (userPatronsTalentData == null) {
            userPatronsTalentData = this.initPatronsTalentData(mallShopType);
        }
        return userPatronsTalentData;
    }

    /**
     * 初始化门客天资数据
     * @param mallShopType
     * @return
     */
    private synchronized ApprenticeUserPatronsTalentData initPatronsTalentData(int mallShopType) {
        ApprenticeUserPatronsTalentData userPatronsTalentData = this.userPatronsTalentDataMap.get(mallShopType);
        if (userPatronsTalentData != null) {
            return userPatronsTalentData;
        }
        //根据mallShopType，占到对应的门客ID
        List<MallInfo> mallInfoList = MallMgr.getMallInfoListByShopType(mallShopType);
        Set<Integer> patronsIds = new HashSet<>();
        for (MallInfo mallInfo : mallInfoList) {
            if (StringUtils.isNullOrEmpty(mallInfo.getReward())) {
                continue;
            }
            Property rewardProp = PropertyHelper.parseStringToProperty(mallInfo.getReward());
            if (rewardProp.isNothing()) {
                continue;
            }
            for (int patronsId : rewardProp.getGoods().keySet()) {
                PatronsInfo patronsInfo = PatronsMgr.getPatronsInfo(patronsId);
                if (patronsInfo != null) {
                    patronsIds.add(patronsId);
                }
            }
        }
        userPatronsTalentData = new ApprenticeUserPatronsTalentData(player.getUserId(), mallShopType, patronsIds);
        this.userPatronsTalentDataMap.put(mallShopType, userPatronsTalentData);
        return userPatronsTalentData;
    }

    /**
     * 天资转换道具
     * @param mallShopType
     * @return
     * @throws BusinessException
     */
    public ApprenticeConvertResult convertTalentToProp(int mallShopType) throws BusinessException {
        //获取天资数据
        ApprenticeUserPatronsTalentData userPatronsTalentData = this.userPatronsTalentDataMap.get(mallShopType);
        if (userPatronsTalentData == null) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_USER_TALENT_NOT_FOUND);
        }
        //判断是否有对应的门客
        UserPatrons targetPatrons = null;
        for (int patronsId : userPatronsTalentData.getPatronsIds()) {
            UserPatrons userPatrons = player.getModule(PatronsModule.class).getUserPatrons(patronsId);
            if (userPatrons != null) {
                targetPatrons = userPatrons;
                break;
            }
        }
        if (targetPatrons == null) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_USER_PATRONS_NOT_FOUND);
        }
        //获取对应的道具ID
        Map<Integer, ApprenticeShopTypePropData> shopTypePropMap = this.getMallShopTypePropMap();
        ApprenticeShopTypePropData shopTypePropData = shopTypePropMap.get(mallShopType);
        if (shopTypePropData == null) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_SHOP_TYPE_PROP_NOT_FOUND);
        }
        int propId = shopTypePropData.getPropId();//转换的道具ID
        long canConvertPropNum = shopTypePropData.getMaxPropNum() - userPatronsTalentData.getConvertPropNum();//可转换道具数
        //判断是否已经达到转换最大值
        if (canConvertPropNum <= 0) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_PROP_MAX);
        }
        //转换道具
        Map<Integer, Long> talentCostMap = new HashMap<>();//天资消耗MAP
        long convertPropNum = this.countConvertPropNum(userPatronsTalentData, targetPatrons.getPatronsId(), canConvertPropNum, talentCostMap);
        if (convertPropNum <= 0) {
            throw BusinessException.newException(GameErrorCode.E_APPRENTICE_TALENT_NOT_ENOUGH);
        }
        //同步天资数据
        this.syncUserPatronsTalentData();
        //添加奖励
        Property property = new Property(propId, convertPropNum);
        player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.Apprentice, eLogMoneyType.ApprenticeTalentConvertReward);
        //日志
        StringBuilder costTalentStr = new StringBuilder();
        for (Map.Entry<Integer, Long> entry : talentCostMap.entrySet()) {
            costTalentStr.append(entry.getKey()).append(":").append(entry.getValue()).append(",");
        }
        LogApprenticeTalentConvertProp log = new LogApprenticeTalentConvertProp(
                player.getUserId(),
                targetPatrons.getPatronsId(),
                costTalentStr.toString(),
                PropertyHelper.parsePropertyToString(property)
        );
        AutoLogMgr.add(log);
        //返回
        return new ApprenticeConvertResult(property, talentCostMap);
    }

    /**
     * 获取商品类型，道具ID MAP
     * @return
     */
    private Map<Integer, ApprenticeShopTypePropData> getMallShopTypePropMap() {
          //获取对应的道具ID
        Map<Integer, ApprenticeShopTypePropData> shopTypePropMap = new HashMap<>();
        String[] shopTypePropStrArr = GameConfig.APPRENTICE_CONVERT_ITEM.split("\\|");
        for (String shopTypePropStr : shopTypePropStrArr) {
            String[] shopTypePropTag =shopTypePropStr.split(";");
            ApprenticeShopTypePropData shopTypePropData = new ApprenticeShopTypePropData(
                    Integer.parseInt(shopTypePropTag[0]),
                    Integer.parseInt(shopTypePropTag[2]),
                    Integer.parseInt(shopTypePropTag[1]),
                    Integer.parseInt(shopTypePropTag[3])
            );
            shopTypePropMap.put(shopTypePropData.getMallShopType(), shopTypePropData);
        }
        return shopTypePropMap;
    }

    /**
     * 计算门客资质加成
     * @param data
     * @param patronsId
     * @return
     */
    private synchronized long countConvertPropNum(ApprenticeUserPatronsTalentData data, int patronsId, long canConvertPropNum, Map<Integer, Long> talentCostMap) {
        PatronsInfo patronsInfo = PatronsMgr.getPatronsInfo(patronsId);
        if (patronsInfo == null) {
            return 0;
        }
        if (canConvertPropNum <= 0) {
            return 0;
        }
        //计算配置
        int pointConvert = GameConfig.APPRENTICE_APPOINT_CAREER_CONVERT;
        int noPointConvert = GameConfig.APPRENTICE_NO_APPOINT_CAREER_CONVERT;
        long propNum = 0;
        //同职业天资转换
        long pointTalent = data.getTalentByType(patronsInfo.getOccupation());
        long pointPropNum = pointTalent / pointConvert;
        if (pointPropNum > canConvertPropNum) {
            pointPropNum = canConvertPropNum;
        }
        if (pointPropNum > 0) {
            long costTalent = pointPropNum * pointConvert;
            canConvertPropNum -= pointPropNum;
            data.addTalent(patronsInfo.getOccupation(), -costTalent);//扣除天资
            talentCostMap.put(patronsInfo.getOccupation(), costTalent);//记录天资消耗
            propNum += pointPropNum;
        }
        //非同职业天资转换
        for (eOccupationType type : eOccupationType.values()) {
            if (type.getValue() == patronsInfo.getOccupation()) {
                continue;
            }
            if (canConvertPropNum <= 0) {
                break;
            }
            long noPointTalent = data.getTalentByType(type.getValue());
            long noPointPropNum = noPointTalent / noPointConvert;
            if (noPointPropNum > canConvertPropNum) {
                noPointPropNum = canConvertPropNum;
            }
            if (noPointPropNum > 0) {
                long costTalent = noPointPropNum * noPointConvert;
                canConvertPropNum -= noPointPropNum;
                data.addTalent(type.getValue(), -costTalent);//扣除天资
                talentCostMap.put((int) type.getValue(), costTalent);//记录天资消耗
                propNum += noPointPropNum;
            }
        }
        //记录已转换的道具数量
        if (propNum > 0) {
            data.setConvertPropNum(data.getConvertPropNum() + propNum);
        }
        return propNum;
    }
}
